


* Replication file for Van der Maat, Eelco. "Genocidal Consolidation: Final Solutions to Elite Rivalry," International Organization
* All analyses were done in Stata/IC 11.0 for Mac.


* This is the Stata replication of the first analysis; it contains:

	* replication of the crosstabs in Table 3 (p 30)
	* replication of the effect estimates (p31)
	* replication of Table A.3 of Appendix C

* For the models of the first analysis in the paper, see the R replication file: "latent.R"


version 11.0
clear all
set mem 500m
capture log close
set more off

* set working directory
cd "/Users/eelco/Dropbox/Academic/Journal submissions/IO 2019/Final Manuscript/IO_GC_replication/IO_GC_replication_I"



****************************************************************************
*** table 3 (page 30)                                                    ***
****************************************************************************


use  "onset_data.dta", clear


tab genonset altcoup_risk, col chi2
tab cgvonset altcoup_risk, col chi2






***************************************************
***                                             ***
*** Effect size replication Analysis 1 (p31)    ***
***                                             ***
***************************************************



use  "onset_data.dta", clear

* set random seed to repeat postestimation outcomes:
set seed 12345

* Table 4, column I � replication of R analysis
probit genonset altcoup_risk lgdppcl lpopl polity guerrilla, cluster(ccode)
fitstat, sav(r2_1)

* Table 4, column II � replication of R analysis
probit cgvonset altcoup_risk lgdppcl lpopl polity guerrilla, cluster(ccode)
fitstat, sav(r2_1)

* Estimate effect of median country 

estsimp probit genonset altcoup_risk lgdppcl lpopl polity guerrilla, cluster(ccode)
setx median
simqi, listx
simqi, fd(pr) changex(altcoup_risk 0 1) listx
setx altcoup_risk 1
simqi, listx


* Estimate effect indonesia 1998

setx median
setx lgdppcl 8.26 
setx lpopl 12.27
setx polity 6
setx guerrilla 1
simqi, listx
setx altcoup_risk 1
simqi, listx





***************************************************
***                                             ***
*** Replication Table A.3 of Appendix C         ***
***                                             ***
***************************************************


*ssc install firthlogit

use  "onset_data.dta", clear




* Col I. Random effects probit;
xtset ccode year
xtprobit genonset altcoup_risk lgdppcl lpopl polity guerrilla, re

* Calculate Nagelkerke Pseudo R^2

	sca llfull= e(ll)
	*intercept only
    xtprobit genonset if e(sample), re
	sca llbase= e(ll)
	display (1-(exp(llbase)/exp(llfull))^(2/e(N))) / (1-(exp(llbase))^(2/e(N)))
	sca drop llfull llbase


* Col II. with splines;

probit genonset altcoup_risk lgdppcl lpopl polity guerrilla mivyr _spline1 _spline2 _spline3, cluster(ccode)
fitstat, sav(r2_1)


* Col III. firth penalized likelihood (instead of rare events logit)

firthlogit genonset altcoup_risk lgdppcl lpopl polity guerrilla


* Calculate Nagelkerke Pseudo R^2

ereturn list
	sca llfull= e(ll)
	*intercept only: 
		* firthlogit logit genonset if e(sample)
		* Problem: constant only model no longer estimates in v1.1 of firthlogit
		* Workaround: create variable that doesn't vary and will therefore be omitted from the model to estimate constant only	
		gen omitted=1
		firthlogit genonset omitted	if e(sample)
	ereturn list
	sca llbase= e(ll)	
	display (1-(exp(llbase)/exp(llfull))^(2/e(N))) / (1-(exp(llbase))^(2/e(N)))
	sca drop llfull llbase
	* exactly same outcome as constant only model in v1


* Col IV. with militias firth logit - non-robust SE;
firthlogit genonset altcoup_risk lgdppcl lpopl polity guerrilla militia

* Calculate Nagelkerke Pseudo R^2

	sca llfull= e(ll)
	*intercept only
		* firthlogit genonset if e(sample)
		* Problem: constant only model no longer estimates in v1.1 of firthlogit
		* Workaround: create variable that doesn't vary and will therefore be omitted from the model to estimate constant only
		firthlogit genonset omitted if e(sample)
	sca llbase= e(ll)
	display (1-(exp(llbase)/exp(llfull))^(2/e(N))) / (1-(exp(llbase))^(2/e(N)))
	sca drop llfull llbase


* Col V. after civil war victory - probit

probit genonset altcoup_risk lgdppcl lpopl polity guerrilla lconflictend, cluster(ccode)
fitstat, sav(r2_1)




* Col VI. with civil conflict;

probit genonset altcoup_risk lgdppcl lpopl polity conflict, cluster(ccode)
fitstat, sav(r2_1)



* Col VII. authoritarian regimes only;

probit genonset altcoup_risk lgdppcl lpopl polity guerrilla if aut==1, cluster(ccode)
fitstat, sav(r2_1)






